var Router = function () {
	
    this.loaded = {};
    this.loadedContent = [];
	
    this.load = function (name) {
        if (this.loadedContent.exists(name)) {
            eval("this.loaded." + name.camelcase(1) + ".restart();");
            return;
        }
        LazyLoad.css('css/' + name + '.css');

        LazyLoad.js(
            ['scripts/' + name + '-layouter.js', 'scripts/' + name + ".js"],
            function () {
                this.loadContent(name);
            },
            null,
            this
       );		
    };
    this.loadContent = function (name) {
        var loader = new tactile.ContentLoader();	
        loader.onsuccess.subscribe((function (e) {
            var content = tactile.Layout.cast(e.loader.getComponent("layout-" + name));
            var root = tactile.page.getComponent("root");
            root.append(content);
            
            var cmd = "this.loaded." + name.camelcase(1) + " = new " + name.camelcase() + "(); this.loaded." + name.camelcase(1) + ".init();";
            eval (cmd);
            this.loadedContent.push(name);
        }).bind(this));
        loader.onerror.subscribe(function(e) { 
            console.log( e ); 
        });
        loader.load( {
            url: "/content/" + name  + ".xml"
        });	
    };	
};